#include<stdio.h>
#include<sys/types.h>
#include<stdlib.h>
#include<sys/stat.h>
#include<unistd.h>
#include<string.h>
#include<fcntl.h>
int main(int argc,char* argv[])
{
    if(argc!=2) exit(2);
    umask(0);
   // int fd=open("log.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
   // dup2(fd,1);
   // printf("hello dup2\n");
   // fprintf(stdout,"hello fprintfstdout\n");
   // write(fd,"hello wirtefd\n",sizeof("hello writefd\n")-1);
    int fd=open(argv[1],O_RDONLY,O_CREAT,0666);
    if(fd<0) exit(1);
    dup2(fd,0);
    close(fd);
    while(1)
    {
        char buffer[2];
        if(!fgets(buffer,sizeof(buffer),stdin)) break;
        printf("%s",buffer);
    }

    return 0;
}
